/*
通用OTDR

2021.7.28 by Menglong Wu
*/
#include "fpga-common.h"
#include "fpga-private.h"
#include "interface/protocal-otdr.h"
#include <math.h>


// TODO 不确定是否需要改动，目前与bsp-otdr.c完全相同


static struct priv_otdr_data data_32k = {
    .cache_len   = 32000 * 4 + 4000,
    .sample_byte = 32 * 1000 * 4,
};

static struct fpga_if otdr_interface_32k = {
    DEFAULT_FPGA_IF,
    .pfun_probe      = cb_fpga_otdr_probe,
    .pfun_release    = cb_fpga_otdr_release,
    .private_data    = &data_32k,
    .name            = "this-otdr-32k",
    .pfun_start      = cb_fpga_otdr_start,
    .pfun_isfinish   = cb_fpga_otdr_isfinish,
    .pfun_stop       = cb_fpga_otdr_stop,
    .pfun_set_gpio   = none_set_gpio,
    .pfun_get_gpio   = none_get_gpio,
    .pfun_version    = com_fpga_version,
    .pfun_read_frame = cb_fpga_read_otdr_data,
    .pfun_write_regs = cb_fpga_otdr_write_regs,
};

static struct priv_otdr_data data_64k = {
    .cache_len   = 64000 * 4 + 4000,
    .sample_byte = 64 * 1000 * 4,
};

static struct fpga_if otdr_interface_64k = {
    DEFAULT_FPGA_IF,
    .pfun_probe      = cb_fpga_otdr_probe,
    .pfun_release    = cb_fpga_otdr_release,
    .private_data    = &data_64k,
    .name            = "this-otdr-64k",
    .pfun_start      = cb_fpga_otdr_start,
    .pfun_isfinish   = cb_fpga_otdr_isfinish,
    .pfun_stop       = cb_fpga_otdr_stop,
    .pfun_set_gpio   = none_set_gpio,
    .pfun_get_gpio   = none_get_gpio,
    .pfun_version    = com_fpga_version,
    .pfun_read_frame = cb_fpga_read_otdr_data,
    .pfun_write_regs = cb_fpga_otdr_write_regs,
};

static void __attribute__((constructor(INIT_BSP))) this_init()
{
    fpga_if_register(&otdr_interface_32k);
    fpga_if_register(&otdr_interface_64k);
}